package com.visionet.school.app.web.wechat.utils;

import com.visionet.school.app.web.common.utils.SpringContextUtil;
import com.visionet.school.app.web.service.wechat.WechatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;




public class GetToken {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	

	
	private static String token;
	
	


	public static void setToken(String token) {
		GetToken.token = token;
	}




	public static String getToken() {
		String token= SpringContextUtil.getBean(WechatService.class).GetToken().getToten();
		return token;
	}
	
	/*
	 * 获取token
	 */
	/*public static   String getToken()
	{
		String toten="";
		try {
			CacheUtil<String> cachetoten=new CacheUtil<String>(110*60);		
			toten=cachetoten.Get("wxtoken");
			System.out.println("toten:"+toten);
			if(toten==null || toten=="")
			{	
				String strUrl=MainVO.GetTokenUrl();
				System.out.println(strUrl);
				URL url = new URL(strUrl);  
			    HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();  
			    InputStreamReader input = new InputStreamReader(httpConn.getInputStream(), "utf-8"); 
			    BufferedReader bufReader = new BufferedReader(input);  
			    String line = "";  
			    StringBuilder contentBuf = new StringBuilder();  
			    while ((line = bufReader.readLine()) != null) {  
			        contentBuf.append(line);  
			    }  
			    String buf = contentBuf.toString();
				String buf=DataTransfer.PostDataToWeiXin(strUrl, null);
			   // System.out.println("access:"+buf);//JSONObject.parse(text)
			   // ClientCredentialVO vo=JSONObject.parseObject("{'errcode':'40001','errmsg':'invalid credential','access_token':'ACCESS_TOKEN','expires_in':'7200'}",ClientCredentialVO.class);
			    ClientCredentialVO vo=JSONObject.parseObject(buf,ClientCredentialVO.class);
				//System.out.println(vo.toString());
				if(vo.getErrcode()==null || vo.getErrcode()=="")
			    {		    	
			    	toten=vo.getAccess_token();				    	
			    	cachetoten.Put("wxtoken", toten,110*60);
			    }
			}
		} catch (Exception e) {
			toten=e.getMessage();
		}
		GetToken a=new GetToken();
		
	
		TokenInitServiceImpl tokeService=new TokenInitServiceImpl();
		TokenBo bo=new TokenBo();
		GetTokenNoStatic b=new 
		bo=tokeService.GetToken();
	
		toten=a.getTokenNoStatic();
		toten=bo.getToten();
		return bb;
		return toten;
	}*/
}
